package com.freedom.rpc.thrift.common.utils;

import org.apache.thrift.protocol.TMultiplexedProtocol;
import org.apache.thrift.transport.TFramedTransport;
import com.freedom.rpc.thrift.common.extended.TransportFieldHelper;
import com.freedom.rpc.thrift.common.socket.MyTSocket;

public class SocketUtils {
	private static final Logger logger = Logger.getLogger(SocketUtils.class);

	public static void setAlive(TMultiplexedProtocol tMultiProtocol, boolean alive, Exception e) {
		try {
			TFramedTransport transport = (TFramedTransport) tMultiProtocol.getTransport();
			MyTSocket myTSocket = (MyTSocket) TransportFieldHelper.get(transport);
			myTSocket.setAlive(alive);
			logger.error("set socket to be not alive --- " + myTSocket.getSocket() + " due to :" + e);
		} catch (Exception e0) {
			logger.error(e0.toString());
		}
	}
}
